//
//  ByBallNoticeDetailCell.m
//  caipiao_ios
//
//  Created by mc on 2018/8/27.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByBallNoticeDetailCell.h"
#import "ByDocumentaryFiveValue.h"
#import "ByDocumentaryFourValue.h"


@implementation ByBallNoticeDetailCell

+ (instancetype)cellWithTableView:(UITableView*)tableView{
    
    static NSString *cellIdentifier = @"ByBallNoticeDetailCell";
    ByBallNoticeDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        self.contentView.backgroundColor = BY_BACKGROUND_COLOR;
    }
    return self;
}


- (void)initViews{
    [self.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    UIView *backgroundView = [[UIView alloc] init];
    [self.contentView addSubview:backgroundView];
    [backgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(5);
        make.right.equalTo(self.contentView).offset(-5);
        make.top.equalTo(self.contentView).offset(0);
        make.bottom.equalTo(self.contentView).offset(-10);
    }];
    backgroundView.layer.cornerRadius = 10;
    backgroundView.backgroundColor = [UIColor whiteColor];
    
    UILabel *titleLabel = [[UILabel alloc] init];
    [backgroundView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(0);
        make.top.equalTo(backgroundView).offset(14);
        make.height.mas_equalTo(@15);
        make.width.mas_equalTo(@80);
    }];
   
    
    titleLabel.font = FONT(14);
    titleLabel.textColor = [UIColor blackColor];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    
   
    
    UILabel *sessionLabel = [[UILabel alloc] init];
    [backgroundView addSubview:sessionLabel];
    [sessionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(0);
        make.top.equalTo(titleLabel.mas_bottom).offset(9);
        make.height.mas_equalTo(@15);
        make.width.mas_equalTo(@80);
    }];
    sessionLabel.text = _netModel.num;
    sessionLabel.textColor = [UIColor blackColor];
    sessionLabel.textAlignment = NSTextAlignmentCenter;
    sessionLabel.font = FONT(14);
    
    
    UILabel *timesLabel = [[UILabel alloc] init];
    [backgroundView addSubview:timesLabel];
    [timesLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(0);
        make.top.equalTo(sessionLabel.mas_bottom).offset(9);
        make.height.mas_equalTo(@15);
        make.width.mas_equalTo(@80);
    }];
    timesLabel.text = _netModel.open_time;
    timesLabel.textColor = [UIColor lightGrayColor];
    timesLabel.textAlignment = NSTextAlignmentCenter;
    timesLabel.font = FONT(12);
    
    

    CGFloat width = (SCREEN_WIDTH - 12 - 80 - 80) / 2.0;
    
    UILabel *teamLabel1 = [[UILabel alloc] init];
    [backgroundView addSubview:teamLabel1];
    [teamLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(titleLabel.mas_right).offset(0);
        make.centerY.equalTo(sessionLabel.mas_centerY).offset(0);
        make.size.mas_equalTo(CGSizeMake(width, 15));
    }];
    teamLabel1.text = _netModel.h_cn_abbr;
    teamLabel1.textColor = [UIColor blackColor];
    teamLabel1.textAlignment = NSTextAlignmentRight;
    teamLabel1.font = FONT(13);
    
    
    UILabel *teamLabel2 = [[UILabel alloc] init];
    [backgroundView addSubview:teamLabel2];
    [teamLabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(backgroundView).offset(0);
        make.centerY.equalTo(sessionLabel.mas_centerY).offset(0);
        make.size.mas_equalTo(CGSizeMake(width, 15));
    }];
    teamLabel2.text = _netModel.a_cn_abbr;
    teamLabel2.textColor = [UIColor blackColor];
    teamLabel2.textAlignment = NSTextAlignmentLeft;
    teamLabel2.font = FONT(13);
    
    
    ByDottedLineView *line = [[ByDottedLineView alloc] init];
    line.direction = DottedLineViewDirectionHorizontalFromRight;
    line.lineColor = BY_LINE_COLOR;
    line.lengthPattern = @[@4, @3];
    [backgroundView addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(0);
        make.right.equalTo(self).offset(0);
        make.top.equalTo(backgroundView).offset(80);
        make.height.mas_equalTo(@1);
    }];
    
    
    UILabel *scoreLabel = [[UILabel alloc] init];
    [backgroundView addSubview:scoreLabel];
   
    scoreLabel.font = FONT(14);
    scoreLabel.textColor = BY_THEME_COLOR;
    scoreLabel.textAlignment = NSTextAlignmentCenter;
    scoreLabel.text = _netModel.final_score;
    
    
    UILabel *halfScoreLabel = [[UILabel alloc] init];
    [backgroundView addSubview:halfScoreLabel];
    [halfScoreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(backgroundView).offset(54);
        make.left.equalTo(teamLabel1.mas_right).offset(0);
        make.right.equalTo(teamLabel2.mas_left).offset(0);
        make.height.mas_equalTo(@13);
    }];
    halfScoreLabel.font = FONT(12);
    halfScoreLabel.textColor = [UIColor lightGrayColor];
    halfScoreLabel.textAlignment = NSTextAlignmentCenter;
    if (_netModel.ball_type.integerValue == 1) {
        
        titleLabel.text = @"竞彩足球";
        halfScoreLabel.text = [NSString stringWithFormat:@"半场%@",_netModel.half_score];
        [scoreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(backgroundView).offset(21);
            make.left.equalTo(teamLabel1.mas_right).offset(0);
            make.right.equalTo(teamLabel2.mas_left).offset(0);
            make.height.mas_equalTo(@15);
        }];
        
    }else if (_netModel.ball_type.integerValue == 2){
        
        titleLabel.text = @"竞彩篮球";
        [scoreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(teamLabel2.mas_centerY).offset(0);
            make.left.equalTo(teamLabel1.mas_right).offset(0);
            make.right.equalTo(teamLabel2.mas_left).offset(0);
            make.height.mas_equalTo(@15);
        }];
    }
    
    
    UIView *grayView = [[UIView alloc] init];
    [backgroundView addSubview:grayView];
    [grayView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(backgroundView).offset(0);
        make.right.equalTo(backgroundView).offset(0);
        make.bottom.equalTo(backgroundView).offset(0);
        make.height.mas_equalTo(@84);
    }];
    grayView.backgroundColor = BY_BACKGROUND_COLOR;
    
    if (_netModel.ball_type.integerValue == 1) {
    
    ByDocumentaryFiveValue *titleView1 = [[ByDocumentaryFiveValue alloc] initWithFrame:CGRectMake(3, 9, SCREEN_WIDTH - 16, 28)];
    [grayView addSubview:titleView1];
    titleView1.valueLabel1.text = @"胜平负";
    titleView1.valueLabel2.text = @"让球";
    titleView1.valueLabel3.text = @"比分";
    titleView1.valueLabel4.text = @"总进球";
    titleView1.valueLabel5.text = @"半全场";
    
    ByDocumentaryFiveValue *valueView = [[ByDocumentaryFiveValue alloc] initWithFrame:CGRectMake(3, titleView1.bottom, SCREEN_WIDTH - 16, 37)];
    [grayView addSubview:valueView];
    valueView.valueLabel1.text = _netModel.jieguo;
    valueView.valueLabel3.text = _netModel.final_score;
    valueView.valueLabel4.text = [NSString stringWithFormat:@"%@",_netModel.zong];
    valueView.valueLabel5.text = _netModel.banquan;
    if (_netModel.let_score.integerValue < 0) {
        valueView.valueLabel2.text = [NSString stringWithFormat:@"(%@)主负",_netModel.let_score];
    }else if (_netModel.let_score.integerValue > 0){
        valueView.valueLabel2.text = [NSString stringWithFormat:@"(%@)主胜",_netModel.let_score];
    }else{
        valueView.valueLabel2.text = @"平";
    }
    valueView.valueLabel1.textColor = [UIColor redColor];
    valueView.valueLabel2.textColor = [UIColor redColor];
    valueView.valueLabel3.textColor = [UIColor redColor];
    valueView.valueLabel4.textColor = [UIColor redColor];
    valueView.valueLabel5.textColor = [UIColor redColor];
    
    CGFloat top = 9;
    for (int i = 0; i< 3; i++) {
        if (i == 1) {
            top = 28 + 9;
        }else if (i == 2){
            top = 9 + 28 + 37;
        }
        UILabel *centerLine = [[UILabel alloc] init];
        [grayView addSubview:centerLine];
        centerLine.backgroundColor = BY_LINE_COLOR;
        [centerLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(grayView).offset(0);
            make.right.equalTo(grayView).offset(0);
            make.top.equalTo(grayView).offset(top);
            make.height.mas_equalTo(@1);
        }];
    }
    
    
    
    for (int i = 0; i < 6; i++) {
        UILabel *line = [[UILabel alloc] init];
        [grayView addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(backgroundView).offset((SCREEN_WIDTH - 16) / 5.0 * i + 3);
            make.top.equalTo(grayView).offset(9);
            make.width.mas_equalTo(@1);
            make.height.mas_equalTo(@65);
        }];
        line.backgroundColor = BY_LINE_COLOR;
    }
        
    }else{
        
        ByDocumentaryFourValue *titleView1 = [[ByDocumentaryFourValue alloc] initWithFrame:CGRectMake(3, 9, SCREEN_WIDTH - 16, 28)];
        [grayView addSubview:titleView1];
        titleView1.valueLabel1.text = @"胜负";
        titleView1.valueLabel2.text = @"让分";
        titleView1.valueLabel3.text = @"大小分";
        titleView1.valueLabel4.text = @"胜负差";
        
        
        ByDocumentaryFourValue *valueView = [[ByDocumentaryFourValue alloc] initWithFrame:CGRectMake(3, titleView1.bottom, SCREEN_WIDTH - 16, 37)];
        [grayView addSubview:valueView];
        valueView.valueLabel1.text = _netModel.win;
        valueView.valueLabel3.text = [NSString stringWithFormat:@"%@",_netModel.zong];
        valueView.valueLabel4.text = [NSString stringWithFormat:@"%@",_netModel.victory];
        valueView.valueLabel2.text = [NSString stringWithFormat:@"%@",_netModel.let_score];
        
        valueView.valueLabel1.textColor = [UIColor redColor];
        valueView.valueLabel2.textColor = [UIColor redColor];
        valueView.valueLabel3.textColor = [UIColor redColor];
        valueView.valueLabel4.textColor = [UIColor redColor];
        
        CGFloat top = 9;
        for (int i = 0; i< 3; i++) {
            if (i == 1) {
                top = 28 + 9;
            }else if (i == 2){
                top = 9 + 28 + 37;
            }
            UILabel *centerLine = [[UILabel alloc] init];
            [grayView addSubview:centerLine];
            centerLine.backgroundColor = BY_LINE_COLOR;
            [centerLine mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(grayView).offset(0);
                make.right.equalTo(grayView).offset(0);
                make.top.equalTo(grayView).offset(top);
                make.height.mas_equalTo(@1);
            }];
        }
        
        
        
        for (int i = 0; i < 5; i++) {
            UILabel *line = [[UILabel alloc] init];
            [grayView addSubview:line];
            [line mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(backgroundView).offset((SCREEN_WIDTH - 16) / 4.0 * i + 3);
                make.top.equalTo(grayView).offset(9);
                make.width.mas_equalTo(@1);
                make.height.mas_equalTo(@65);
            }];
            line.backgroundColor = BY_LINE_COLOR;
        }
    }
    
}
- (void)setNetModel:(ByNetModel *)netModel{
    _netModel = netModel;
    [self initViews];
}


@end
